<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>景点管理</title>
    <link rel="stylesheet" type="text/css" href="/tourismsystem/css/query.css">
    <script type="text/javascript" src="/tourismsystem/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var param = new URLSearchParams(window.location.search);
            var pageNo = param.get("pageNo");
            var likeValue = param.get("likeValue");
            selectByPage(pageNo, likeValue);

            // 点击查询按钮
            $("#selectByLikeValue").click(function () {
                var likevaluestr = $.trim($("#likevaluestr").val());
                selectByPage(1, likevaluestr);
            });

            function selectByPage(pageNo, likeValue) {
                var url = "/tourismsystem/selectByPage.spot";
                var paramObj = {
                    "pageNo": pageNo || 1,
                    "likeValue": likeValue || ""
                };
                $.post(url, paramObj, function (data) {
                    // if (data == "") {
                    //     window.parent.location.href = "/fiction_platform0808/login.html";
                    // }
                    $("#tbodyList").empty();
                    var jsonObj = JSON.parse(data);
                    var recordList = jsonObj.recordList;

                    for (var i = 0; i < recordList.length; i++) {
                        var isHotText = recordList[i].is_hot == 1 ? "是" : "否";
                        $("<tr>" +
                            "<td>" + recordList[i].sight_id + "</td>" +
                            "<td>" + recordList[i].sight_name + "</td>" +
                            "<td>" + recordList[i].city + "</td>" +
                            "<td>" + recordList[i].introduction + "</td>" +
                            "<td>" + recordList[i].img_path + "</td>" +
                            "<td>" + isHotText + "</td>" +
                            "<td><a href='/tourismsystem/toEdit.spot?sight_id=" + recordList[i].sight_id + "'>编辑</a></td>" +
                            "<td><a href='/tourismsystem/DeleteBySightId.spot?sight_id=" + recordList[i].sight_id + "' onclick='confirmDelete(event,this)'>删除</a></td>" +
                            "</tr>").appendTo($("#tbodyList"));
                    }

                    $("#likevaluestr").val(jsonObj.likeValue); // 回填查询条件
                    $("#recordCount").text(jsonObj.recordCount); // 总记录数
                    $("#totalPages").text(jsonObj.totalPages);   // 总页数
                    $("#pageNo").text(jsonObj.pageNo);           // 当前页数

                    // 分页链接拼接
                    var baseUrl = "/tourismsystem/toList.spot?likeValue=" + jsonObj.likeValue;
                    $("#firstPage").prop("href", baseUrl + "&pageNo=1");
                    $("#prev").prop("href", baseUrl + "&pageNo=" + ((jsonObj.pageNo - 1) > 0 ? (jsonObj.pageNo - 1) : 1));
                    $("#nextPage").prop("href", baseUrl + "&pageNo=" + ((jsonObj.pageNo + 1) < jsonObj.totalPages ? (jsonObj.pageNo + 1) : jsonObj.totalPages));
                    $("#tailPage").prop("href", baseUrl + "&pageNo=" + jsonObj.totalPages);
                });
            }

        });
        function confirmDelete(event, aNode) {
            var sightName = $(aNode).parent().parent().find("td").eq(1).text();
            if (!confirm("确定删除" + sightName + "的景点信息吗？")) {
                event.preventDefault();
                return false;
            }
        }
    </script>
</head>
<body>
<div id="top">当前位置:景点管理---查看景点信息</div>
<div id="contexttop">
    <table id="tab" border="1">
        <tr>
            <td colspan="7" height="50">
                <input type="text" id="likevaluestr" title="景点ID、名称、城市" placeholder="景点ID、名称、城市">
                <input type="button" value="查询" id="selectByLikeValue">
            </td>
        </tr>
        <tr bgcolor="#cccccc">
            <th>景点ID</th>
            <th>景点名称</th>
            <th>所在城市</th>
            <th>简介</th>
            <th>图片路径</th>
            <th>是否热门</th>
            <th colspan="2">操作</th>
        </tr>
        <tbody id="tbodyList"></tbody>
    </table>
</div>
<div align="center" id="contextbotton">
    &nbsp;总记录数&nbsp;<span id="recordCount"></span>&nbsp;条&nbsp;共&nbsp;<span id="totalPages"></span>&nbsp;页&nbsp;
    <a id="firstPage" href="#">首页</a>&nbsp;
    <a id="prev" href="#">上一页</a>&nbsp;
    <a id="nextPage" href="#">下一页</a>&nbsp;
    <a id="tailPage" href="#">尾页</a>&nbsp;
    第&nbsp;<span id="pageNo"></span>&nbsp;页&nbsp;
</div>
</body>
</html>